package com.itclass.test;

import java.time.Duration;
import java.time.LocalDateTime;

public class TimeToInteger {

    private static Integer MAX_VALUE = 10000;
    private static Integer MIN_VALUE = 100;
    public static int generateIntValue(LocalDateTime currentTime, LocalDateTime lastTime) {
        Duration duration = Duration.between(lastTime, currentTime);

        long timeInterval = Math.max(1, duration.toMillis()); // 获取时间间隔数（毫秒），最小为 1
        // 得到相差分钟数
        long minutes = timeInterval / (1000 * 60); //将毫秒数转换为分钟数


        int count = (int) (MAX_VALUE & minutes);


        // 根据时间间隔数进行映射到整数值的范围，并确保最小为 100

        return MAX_VALUE & (count | MIN_VALUE) ;
    }

    public static void main(String[] args) {

        LocalDateTime lastTime = LocalDateTime.of(2024, 3, 15, 14, 10); // 示例最后时间
        LocalDateTime currentTime = LocalDateTime.of(2024, 3, 15, 15, 10); // 示例最后时间

        int generatedInt = generateIntValue(currentTime, lastTime);

        System.out.println("Generated Integer Value: " + generatedInt);
    }
}
